package com.intexh.quickandroid.module.chat.ui.messageItemView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.intexh.quickandroid.R;
import com.intexh.quickandroid.module.chat.ChatHelper;
import com.intexh.quickandroid.module.chat.bean.ChatMessage;
import com.intexh.quickandroid.module.chat.ui.face.EmojiFactory;


/**
 * Created by engine on 13-12-17.
 */
public class TextMessageItem extends AbsChatItem {

    private View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(final View view) {
           /* AlertDialog.Builder builder = new AlertDialog.Builder(mContext, AlertDialog.THEME_HOLO_LIGHT);
            builder.setTitle(R.string.choice)
                    .setItems(R.array.choices, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            ClipboardManager cmb = (ClipboardManager) mContext.getSystemService(mContext.CLIPBOARD_SERVICE);
                            cmb.setText(((TextView) view).getText().toString());
                        }
                    });
            builder.create().show();*/
            return false;
        }
    };


    public TextMessageItem(Context context, ChatMessage message, boolean needTime) {
        this(context, message, needTime, false);
    }

    public TextMessageItem(Context context, ChatMessage message, boolean needTime, boolean isNearChat) {
        super(context);
        this.mNeedTime = needTime;
        this.mMessage = message;
        this.mContext = context;
       if (ChatHelper.getInstance().getUserInfo().getUid().equals(message.getUid())) {//发出去的
            LayoutInflater.from(context).inflate(R.layout.message_item_to, this);
        } else {//接收到的
            LayoutInflater.from(context).inflate(R.layout.message_item_from, this);
        }
        setLayout();
    }

    private void setLayout() {
        setCommonLayout();
        TextView contentTextView = (TextView) findViewById(R.id.session_content);
        /*if(mMessage.getContent().length() <= 2)
            contentTextView.setGravity(Gravity.CENTER);*/
        contentTextView.setText(EmojiFactory.convertToEmojiText(contentTextView.getContext(), mMessage.getContent()));
        contentTextView.setOnLongClickListener(onLongClickListener);
    }

}
